package com.rg1906.web;

import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.rg1906.entity.Teacher;
import com.rg1906.service.impl.TeacherListServiceImpl;


@WebServlet("/TeacherList")
public class TeacherList extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	TeacherListServiceImpl service=new TeacherListServiceImpl();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String pageNumber;
		String pageSize;
		 pageNumber = request.getParameter("pageNumber");
		 pageSize = request.getParameter("pageSize");
		if(pageNumber==null||pageSize==null) {
			pageNumber="0";
			pageSize="3";
		}
		String likeName = request.getParameter("likeName");
		String teacherNum = request.getParameter("teacherNum");
		String gradeName = request.getParameter("gradeName");
		HashMap<String,Object> map = new HashMap<>();
		try {
			List<Teacher> list = service.QueryTeacher(pageNumber,pageSize,likeName,teacherNum,gradeName);
			Long total = service.getCount(likeName,teacherNum,gradeName);
			map.put("total", total);
			map.put("rows", list);
			response.getWriter().print(JSON.toJSONString(map));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		doGet(request, response);
	}

}
